.class Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;
.super Lcom/burstly/lib/network/request/DefaultRequestCallback;
.source "UpdateCurrencyCallback.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$1;,
        Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;
    }
.end annotation

.annotation system Ldalvik/annotation/Signature;
    value = {
        "Lcom/burstly/lib/network/request/DefaultRequestCallback",
        "<",
        "Lcom/burstly/lib/currency/request/AccountInfoResponse;",
        ">;"
    }
.end annotation


# static fields
.field static final LOG:Lcom/burstly/lib/util/LoggerExt;

.field static final TAG:Ljava/lang/String;


# instance fields
.field private final mCurrencyListeners:Ljava/util/List;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/List",
            "<",
            "Lcom/burstly/lib/feature/currency/ICurrencyListener;",
            ">;"
        }
    .end annotation
.end field

.field private final mUserAccount:Lcom/burstly/lib/currency/UserAccount;


# direct methods
.method static constructor <clinit>()V
    .locals 1

    .prologue
    .line 40
    invoke-static {}, Lcom/burstly/lib/util/LoggerExt;->getInstance()Lcom/burstly/lib/util/LoggerExt;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->LOG:Lcom/burstly/lib/util/LoggerExt;

    .line 45
    const-class v0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;

    invoke-virtual {v0}, Ljava/lang/Class;->getSimpleName()Ljava/lang/String;

    move-result-object v0

    sput-object v0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->TAG:Ljava/lang/String;

    return-void
.end method

.method constructor <init>(Ljava/util/List;Lcom/burstly/lib/currency/UserAccount;)V
    .locals 0
    .parameter
    .parameter "userAccount"
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/List",
            "<",
            "Lcom/burstly/lib/feature/currency/ICurrencyListener;",
            ">;",
            "Lcom/burstly/lib/currency/UserAccount;",
            ")V"
        }
    .end annotation

    .prologue
    .line 82
    .local p1, currencyListeners:Ljava/util/List;,"Ljava/util/List<Lcom/burstly/lib/feature/currency/ICurrencyListener;>;"
    invoke-direct {p0}, Lcom/burstly/lib/network/request/DefaultRequestCallback;-><init>()V

    .line 83
    iput-object p1, p0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->mCurrencyListeners:Ljava/util/List;

    .line 84
    iput-object p2, p0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->mUserAccount:Lcom/burstly/lib/currency/UserAccount;

    .line 85
    return-void
.end method

.method private createRequestResult(Lcom/burstly/lib/currency/request/AccountInfoResponse;)Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;
    .locals 13
    .parameter "response"

    .prologue
    .line 127
    const/4 v8, 0x0

    .line 128
    .local v8, result:Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;
    if-eqz p1, :cond_3

    const-string v9, "0"

    invoke-virtual {p1}, Lcom/burstly/lib/currency/request/AccountInfoResponse;->getStatusCode()Ljava/lang/String;

    move-result-object v10

    invoke-virtual {v9, v10}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v9

    if-eqz v9, :cond_3

    .line 129
    invoke-virtual {p1}, Lcom/burstly/lib/currency/request/AccountInfoResponse;->getAccounts()[Lcom/burstly/lib/currency/request/AccountInfoResponse$AccountBean;

    move-result-object v1

    .line 130
    .local v1, accounts:[Lcom/burstly/lib/currency/request/AccountInfoResponse$AccountBean;
    if-eqz v1, :cond_1

    array-length v9, v1

    if-eqz v9, :cond_1

    .line 133
    move-object v2, v1

    .local v2, arr$:[Lcom/burstly/lib/currency/request/AccountInfoResponse$AccountBean;
    array-length v7, v2

    .local v7, len$:I
    const/4 v6, 0x0

    .local v6, i$:I
    :goto_0
    if-ge v6, v7, :cond_2

    aget-object v0, v2, v6

    .line 134
    .local v0, accBean:Lcom/burstly/lib/currency/request/AccountInfoResponse$AccountBean;
    invoke-virtual {v0}, Lcom/burstly/lib/currency/request/AccountInfoResponse$AccountBean;->getCurrency()Ljava/lang/String;

    move-result-object v5

    .line 135
    .local v5, currency:Ljava/lang/String;
    iget-object v9, p0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->mUserAccount:Lcom/burstly/lib/currency/UserAccount;

    invoke-virtual {v9, v5}, Lcom/burstly/lib/currency/UserAccount;->getCurrencyAccount(Ljava/lang/String;)Lcom/burstly/lib/currency/UserCurrencyAccount;

    move-result-object v3

    .line 136
    .local v3, currInfo:Lcom/burstly/lib/currency/UserCurrencyAccount;
    if-nez v3, :cond_0

    .line 137
    new-instance v4, Lcom/burstly/lib/currency/UserCurrencyAccount;

    invoke-direct {v4, v5}, Lcom/burstly/lib/currency/UserCurrencyAccount;-><init>(Ljava/lang/String;)V

    .line 138
    .local v4, currecnyAccount:Lcom/burstly/lib/currency/UserCurrencyAccount;
    invoke-virtual {v0}, Lcom/burstly/lib/currency/request/AccountInfoResponse$AccountBean;->getBalance()I

    move-result v9

    invoke-virtual {v4, v9}, Lcom/burstly/lib/currency/UserCurrencyAccount;->setTotalCurrencyAmount(I)V

    .line 139
    iget-object v9, p0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->mUserAccount:Lcom/burstly/lib/currency/UserAccount;

    invoke-virtual {v9, v5, v4}, Lcom/burstly/lib/currency/UserAccount;->setCurrencyAccount(Ljava/lang/String;Lcom/burstly/lib/currency/UserCurrencyAccount;)V

    .line 144
    .end local v4           #currecnyAccount:Lcom/burstly/lib/currency/UserCurrencyAccount;
    :goto_1
    invoke-static {}, Lcom/burstly/lib/currency/UserAccountStorage;->getInstance()Lcom/burstly/lib/currency/UserAccountStorage;

    move-result-object v9

    iget-object v10, p0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->mUserAccount:Lcom/burstly/lib/currency/UserAccount;

    invoke-virtual {v9, v10}, Lcom/burstly/lib/currency/UserAccountStorage;->saveAccount(Lcom/burstly/lib/currency/UserAccount;)V

    .line 133
    add-int/lit8 v6, v6, 0x1

    goto :goto_0

    .line 141
    :cond_0
    invoke-virtual {v3}, Lcom/burstly/lib/currency/UserCurrencyAccount;->getActualBalance()I

    move-result v9

    invoke-virtual {v3, v9}, Lcom/burstly/lib/currency/UserCurrencyAccount;->setOldTotalCurrencyAmount(I)V

    .line 142
    invoke-virtual {v0}, Lcom/burstly/lib/currency/request/AccountInfoResponse$AccountBean;->getBalance()I

    move-result v9

    invoke-virtual {v3, v9}, Lcom/burstly/lib/currency/UserCurrencyAccount;->setTotalCurrencyAmount(I)V

    goto :goto_1

    .line 147
    .end local v0           #accBean:Lcom/burstly/lib/currency/request/AccountInfoResponse$AccountBean;
    .end local v2           #arr$:[Lcom/burstly/lib/currency/request/AccountInfoResponse$AccountBean;
    .end local v3           #currInfo:Lcom/burstly/lib/currency/UserCurrencyAccount;
    .end local v5           #currency:Ljava/lang/String;
    .end local v6           #i$:I
    .end local v7           #len$:I
    :cond_1
    sget-object v9, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->LOG:Lcom/burstly/lib/util/LoggerExt;

    sget-object v10, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->TAG:Ljava/lang/String;

    const-string v11, "Server returned no accounts"

    const/4 v12, 0x0

    new-array v12, v12, [Ljava/lang/Object;

    invoke-virtual {v9, v10, v11, v12}, Lcom/burstly/lib/util/LoggerExt;->logWarning(Ljava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    .line 156
    :cond_2
    invoke-direct {p0}, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->succeeded()Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;

    move-result-object v8

    .line 159
    .end local v1           #accounts:[Lcom/burstly/lib/currency/request/AccountInfoResponse$AccountBean;
    :cond_3
    if-nez v8, :cond_4

    .line 160
    invoke-direct {p0}, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->failed()Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;

    move-result-object v8

    .line 162
    :cond_4
    return-object v8
.end method

.method private failed()Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;
    .locals 2

    .prologue
    .line 183
    invoke-direct {p0}, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->succeeded()Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;

    move-result-object v0

    .line 184
    .local v0, result:Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;
    const/4 v1, 0x0

    iput-boolean v1, v0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;->mSucceeded:Z

    .line 185
    return-object v0
.end method

.method private processResult(Lcom/burstly/lib/currency/request/AccountInfoResponse;)V
    .locals 6
    .parameter "response"

    .prologue
    .line 103
    invoke-direct {p0, p1}, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->createRequestResult(Lcom/burstly/lib/currency/request/AccountInfoResponse;)Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;

    move-result-object v3

    .line 104
    .local v3, updateEvent:Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;
    iget-object v4, p0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->mCurrencyListeners:Ljava/util/List;

    invoke-interface {v4}, Ljava/util/List;->isEmpty()Z

    move-result v4

    if-nez v4, :cond_0

    .line 106
    :try_start_0
    iget-object v4, p0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->mCurrencyListeners:Ljava/util/List;

    invoke-interface {v4}, Ljava/util/List;->iterator()Ljava/util/Iterator;

    move-result-object v1

    .local v1, i$:Ljava/util/Iterator;
    :goto_0
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_0

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v2

    check-cast v2, Lcom/burstly/lib/feature/currency/ICurrencyListener;

    .line 107
    .local v2, listener:Lcom/burstly/lib/feature/currency/ICurrencyListener;
    iget-boolean v4, v3, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;->mSucceeded:Z

    if-eqz v4, :cond_1

    .line 108
    iget-object v4, v3, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;->mUpdateEvent:Ljava/util/Map;

    invoke-interface {v2, v4}, Lcom/burstly/lib/feature/currency/ICurrencyListener;->didUpdateBalance(Ljava/util/Map;)V
    :try_end_0
    .catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_0

    .line 114
    .end local v1           #i$:Ljava/util/Iterator;
    .end local v2           #listener:Lcom/burstly/lib/feature/currency/ICurrencyListener;
    :catch_0
    move-exception v0

    .line 115
    .local v0, exception:Ljava/lang/Exception;
    sget-object v4, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->LOG:Lcom/burstly/lib/util/LoggerExt;

    sget-object v5, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->TAG:Ljava/lang/String;

    invoke-virtual {v4, v5, v0}, Lcom/burstly/lib/util/LoggerExt;->logThrowable(Ljava/lang/String;Ljava/lang/Throwable;)V

    .line 118
    .end local v0           #exception:Ljava/lang/Exception;
    :cond_0
    return-void

    .line 110
    .restart local v1       #i$:Ljava/util/Iterator;
    .restart local v2       #listener:Lcom/burstly/lib/feature/currency/ICurrencyListener;
    :cond_1
    :try_start_1
    iget-object v4, v3, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;->mUpdateEvent:Ljava/util/Map;

    invoke-interface {v2, v4}, Lcom/burstly/lib/feature/currency/ICurrencyListener;->didFailToUpdateBalance(Ljava/util/Map;)V
    :try_end_1
    .catch Ljava/lang/Exception; {:try_start_1 .. :try_end_1} :catch_0

    goto :goto_0
.end method

.method private succeeded()Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;
    .locals 2

    .prologue
    .line 171
    new-instance v0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;

    const/4 v1, 0x0

    invoke-direct {v0, v1}, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;-><init>(Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$1;)V

    .line 172
    .local v0, result:Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;
    const/4 v1, 0x1

    iput-boolean v1, v0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;->mSucceeded:Z

    .line 173
    iget-object v1, p0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->mUserAccount:Lcom/burstly/lib/currency/UserAccount;

    invoke-virtual {v1}, Lcom/burstly/lib/currency/UserAccount;->getAllCurrencyAccounts()Ljava/util/Map;

    move-result-object v1

    invoke-static {v1}, Lcom/burstly/lib/currency/BalanceUpdateInfo;->createFrom(Ljava/util/Map;)Ljava/util/Map;

    move-result-object v1

    iput-object v1, v0, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback$RequestResult;->mUpdateEvent:Ljava/util/Map;

    .line 174
    return-object v0
.end method


# virtual methods
.method public onFailInBackground(Lcom/burstly/lib/currency/request/AccountInfoResponse;)V
    .locals 0
    .parameter "processResult"

    .prologue
    .line 94
    invoke-direct {p0, p1}, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->processResult(Lcom/burstly/lib/currency/request/AccountInfoResponse;)V

    .line 95
    return-void
.end method

.method public bridge synthetic onFailInBackground(Ljava/lang/Object;)V
    .locals 0
    .parameter "x0"

    .prologue
    .line 35
    check-cast p1, Lcom/burstly/lib/currency/request/AccountInfoResponse;

    .end local p1
    invoke-virtual {p0, p1}, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->onFailInBackground(Lcom/burstly/lib/currency/request/AccountInfoResponse;)V

    return-void
.end method

.method public onSuccessInBackground(Lcom/burstly/lib/currency/request/AccountInfoResponse;)V
    .locals 0
    .parameter "processResult"

    .prologue
    .line 89
    invoke-direct {p0, p1}, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->processResult(Lcom/burstly/lib/currency/request/AccountInfoResponse;)V

    .line 90
    return-void
.end method

.method public bridge synthetic onSuccessInBackground(Ljava/lang/Object;)V
    .locals 0
    .parameter "x0"

    .prologue
    .line 35
    check-cast p1, Lcom/burstly/lib/currency/request/AccountInfoResponse;

    .end local p1
    invoke-virtual {p0, p1}, Lcom/burstly/lib/currency/request/UpdateCurrencyCallback;->onSuccessInBackground(Lcom/burstly/lib/currency/request/AccountInfoResponse;)V

    return-void
.end method
